﻿using Model;
using NUnit.Framework;

namespace UnitTests
{
    [TestFixture]
    public class GeneratorRobustnessTests
    {
        [Test]
        [System.ComponentModel.Description("Requirement:  Bulletproof. The generator must never crash or throw.  If it cannot produce a result, it must return an empty string.")]
        public void DefaultValuesResultInZeroLengthString()
        {
            PasswordGenerationInfo info = new PasswordGenerationInfo();
            IPasswordGenerator ipg = new PasswordGenerator();
            string testResult = ipg.GeneratePassword(info);
            Assert.IsTrue(testResult.Length==0);
        }
        [Test]
        public void AskingForPasswordOfNegativeLength()
        {
            PasswordGenerationInfo info = new PasswordGenerationInfo {Length = -1};
            IPasswordGenerator ipg = new PasswordGenerator();
            string testResult = ipg.GeneratePassword(info);
            Assert.IsTrue(testResult.Length == 0);
        }
        [Test]
        public void AttemptingToObtainTooLongPassword()
        {
            PasswordGenerationInfo info = new PasswordGenerationInfo { Length = 200 };
            IPasswordGenerator ipg = new PasswordGenerator();
            string testResult = ipg.GeneratePassword(info);
            Assert.IsTrue(testResult.Length == 0);
        }
        [Test]
        public void AttemptingToObtainTooShortPassword()
        {
            PasswordGenerationInfo info = new PasswordGenerationInfo { Length = 2 };
            IPasswordGenerator ipg = new PasswordGenerator();
            string testResult = ipg.GeneratePassword(info);
            Assert.IsTrue(testResult.Length == 0);
        }
        [Test]
        public void ValidRequests()
        {
            IPasswordGenerator ipg = new PasswordGenerator();
            for (int i = ipg.MinimumLength; i <= ipg.MaximumLength; i++)
            {
                PasswordGenerationInfo info = new PasswordGenerationInfo {Length = i, UseLeftHand = true, UseRightHand = true, UseSymbols = true};
                string testResult = ipg.GeneratePassword(info);
                Assert.IsTrue(testResult.Length == i);
                Assert.IsTrue(testResult != testResult.ToLower());
                Assert.IsTrue(testResult != testResult.ToUpper());
            }
        }
    }
}
